package com.neusoft.nep.NEPM.controller;
import com.neusoft.tools.AlertUtils;
import com.neusoft.tools.FXMLUtils;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import com.neusoft.nep.entity.nepsFeedback;
public class detailOfAqiViewController{
    @FXML
    private TextField txt_number,txt_name,txt_phonenumber,txt_date,txt_address,txt_content,txt_level;
    public nepsFeedback n;
    @FXML
    private nepsFeedback nepsf;
    @FXML
    private Button btn_out,back;
    @FXML
    private TreeView treeview;
    @FXML
    private TreeItem To_AqiTrendTotalStatisView;
    @FXML
    private TreeItem To_AqiSeperatedStatisView;
    @FXML
    private TreeItem To_OtherStatisView;
    @FXML
    private TreeItem To_ProvinceDataTotalStatisView;
    @FXML
    TreeItem To_confirmDataView;
    @FXML
    TreeItem To_publicAqiDataList;
    @FXML
    public void initialize(){

        treeview.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue == To_AqiSeperatedStatisView) {
                try {
                    FXMLUtils.switchToShow(btn_out,"NEPM/view/AqiSeperatedStatisView.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }
            } else if (newValue == To_AqiTrendTotalStatisView) {
                try {
                    FXMLUtils.switchToShow(btn_out,"NEPM/view/AqiTrendTotalStatisView.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }
            } else if (newValue == To_OtherStatisView) {
                try {
                    FXMLUtils.switchToShow(btn_out,"NEPM/view/OtherStatisView.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }
            } else if (newValue == To_ProvinceDataTotalStatisView) {
                try {
                    FXMLUtils.switchToShow(btn_out,"NEPM/view/ProvinceDataTotalStatisView.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }

            }

            else if (newValue == To_confirmDataView) {
                try {
                    FXMLUtils.switchToShow(btn_out, "NEPM/view/confirmDataView.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }
            }else if (newValue == To_publicAqiDataList) {
                try {
                    FXMLUtils.switchToShow(btn_out, "NEPM/view/publicAqiDataList.fxml");
                } catch (IOException e) {
                    e.printStackTrace();
                    AlertUtils.showDialog("错误", "页面跳转失败: " + e.getMessage());
                }
            }
        });
    }
    public void Log_out() throws IOException {
        FXMLUtils.switchToShow(btn_out,"NEPM/view/LoginView.fxml");
    }
    public nepsFeedback set(nepsFeedback n){
        nepsf=n;
        return nepsf;
    }
    public void back() throws IOException {
        FXMLLoader fxmlLoader=new FXMLLoader();
        URL url=getClass().getResource("../view/publicAqiDataList.fxml");
        fxmlLoader.setLocation(url);
        Parent root = fxmlLoader.load();
        Scene scene=new Scene(root);
        Stage stage = (Stage)back.getScene().getWindow();
        stage.setScene(scene);
        stage.show();
    }
    public void setNepsFeedback(nepsFeedback feedback) {
        if (feedback != null) {
           txt_address.setText(feedback.getProvince()+"  "+feedback.getCity()+"  "+feedback.getAddress());
           txt_content.setText(feedback.getContent());
           txt_level.setText(feedback.getLevel());
           txt_name.setText(feedback.getUsername());
           txt_number.setText(Integer.toString(feedback.getNumber()));
           txt_phonenumber.setText(feedback.getPhoneNumber());
           txt_date.setText(feedback.getDate());
            }
    }

}


